package com.dfxs.sqlSession;

import com.dfxs.config.XMLConfigBuilder;
import com.dfxs.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author zhangdongsheng
 * @version 1.0
 * @describe 构建数据库会话工厂
 * @date 2020/9/25 23:53
 */
public class SqlSessionFactoryBuilder {


    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException {
        // 第一：使用dom4j解析配置文件，将解析出来的内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        // 第二：创建sqlSessionFactory对象：工厂类：生产sqlSession:会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
